﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for cls_tbQUYEN
/// </summary>
public class cls_tbQUYEN
{
	public cls_tbQUYEN()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    //public static string quyen = "0";
    public static DataTable GetAll()
    {
        DataTable table = new DataTable();
        av.dal.SqlDataProvider clsSQL = new av.dal.SqlDataProvider();
        //SqlParameter[] parameter = new SqlParameter[1];
        //parameter[0] = new SqlParameter("@Id_Admin", adminID);
        try
        {
            //table = clsSQL.GetDataFrom("ADMIN_GetAllAdmin", CommandType.StoredProcedure, null);
            table = clsSQL.GetDataFrom("tbQUYEN_GetAll", CommandType.StoredProcedure, null);

        }
        catch  { }
        return table;
    }
    public static DataTable Get(int F_STTQUYEN)
    {
        DataTable table = new DataTable();
        av.dal.SqlDataProvider clsSQL = new av.dal.SqlDataProvider();
        SqlParameter[] parameter = new SqlParameter[1];
        parameter[0] = new SqlParameter("@F_STTQUYEN", F_STTQUYEN);
        try
        {
            table = clsSQL.GetDataFrom("tbQUYEN_Get", CommandType.StoredProcedure, parameter);
        }
        catch { }
        return table;
    }
    public static string GetF_TENQUYEN(int F_STTQUYEN)
    {
        string rs = "";
        DataTable dt = new DataTable();
        dt = Get(F_STTQUYEN);
        if (dt.Rows.Count > 0)
        {
            rs = dt.Rows[0]["F_TENQUYEN"].ToString();
        }
        return rs;
    }
    public static string InsertUpdate(int F_STTQUYEN, string F_TENQUYEN)
    {
        av.dal.SqlDataProvider clsSQL = new av.dal.SqlDataProvider();
        object[] myValue = { F_STTQUYEN, F_TENQUYEN };
        string[] myPara = { "@F_STTQUYEN", "@F_TENQUYEN" };
        SqlParameter[] Parameter = new SqlParameter[myPara.Length];
        for (int i = 0; i < myPara.Length; i++)
        {
            Parameter[i] = new SqlParameter(myPara[i], myValue[i]);
        }
        try
        {
            if (clsSQL.ExecuteNonQuery("tbQUYEN_InsertUpdate", CommandType.StoredProcedure, Parameter) > 0)
                return "OK";
            else
                return "NO";
        }
        catch (SqlException ex) { return ex.Message; }
    }
    public static string Delete(int F_STTQUYEN)
    {
        av.dal.SqlDataProvider clsSQL = new av.dal.SqlDataProvider();
        object[] myValue = { F_STTQUYEN };
        string[] myPara = { "@F_STTQUYEN" };
        SqlParameter[] Parameter = new SqlParameter[myPara.Length];
        for (int i = 0; i < myPara.Length; i++)
        {
            Parameter[i] = new SqlParameter(myPara[i], myValue[i]);
        }
        try
        {
            if (clsSQL.ExecuteNonQuery("tbQUYEN_Delete", CommandType.StoredProcedure, Parameter) > 0)
                return "OK";
            else
                return "NO";
        }
        catch (SqlException ex) { return ex.Message; }
    }
}